package com.xxtx.trade.common.utils;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.security.NoSuchAlgorithmException;
import java.util.Map;

/**
 * 功能描述:
 *
 * @Params:
 * @Author: xuliang
 * @email: northly@live.com
 * @Date: 2019/12/4 16:09
 */
@Component
public class IdCardUtils {

    static  final Logger logger = LoggerFactory.getLogger(IdCardUtils.class);

    private final static String appid = "rjbOouOWKITuQ4CS";

    private final static String appSecurity = "rjbOouOWKITuQ4CSvkgh5wIM9Phx6m5l";


    /**
     *
     * @param name
     * @param mobile
     * @param idcard
     * @return
     * @throws NoSuchAlgorithmException
     */
    public static ResponseVo<Map<String,Object>> checkIdCard(String name,String mobile,String idcard) throws NoSuchAlgorithmException {
        long timestamp = System.currentTimeMillis();
        String sign = MD5.MD5_32bit(appid + "&" + timestamp + "&" + appSecurity);
        String url = "https://api.shumaidata.com/v2/mobile_three/check?appid="+appid+"&timestamp="+timestamp+"&sign="+sign+"&name="+name+"&idcard="+idcard+"&mobile="+mobile;
        String response = HttpClient.get(url);

        logger.info("checkIdCard:{}",response);
        if(!StringUtils.isEmpty(response)){
            return JSON.parseObject(response, ResponseVo.class);
//            if(rv.isSuccess()){
//                if(rv.getCode() == 200){
//                   Object val = rv.getData().get("result");
//                    System.out.println( rv.getData());
//                   return Integer.parseInt(val+"");
//                }else{
//                    return rv.getCode();
//                }
//            }
        }

        return null;
    }

    public static void main(String[] args) throws NoSuchAlgorithmException {
//        习武
//        412723199903032931
//        15896757225

//        王兵 15649909785	411425198908206053 {"order_no":"654325612097441792","result":"0","desc":"一致","channel":null,"province":null,"city":null,"sex":"男","birthday":"19890820","address":"河南省商丘市虞城县"}
//        陈义刚 18589329269	410725199201192014 {"order_no":"654325742678708224","result":"0","desc":"一致","channel":null,"province":null,"city":null,"sex":"男","birthday":"19920119","address":"河南省新乡市原阳县"}
//        王斌 13888584999	532527199202052057 {"order_no":"654325854100393984","result":"0","desc":"一致","channel":null,"province":null,"city":null,"sex":"男","birthday":"19920205","address":"云南省红河哈尼族彝族自治州泸西县"}
//        林章宝 17750213004	352201199012120035 {"order_no":"654325992986382336","result":"0","desc":"一致","channel":null,"province":null,"city":null,"sex":"男","birthday":"19901212","address":"福建省宁德地区宁德市"}
        System.out.println(checkIdCard("孟小帅","18903773810","411381199501250837"));
    }
}
